<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<jsp:include page="../frame/header.jsp"></jsp:include>

<title>群组话题管理</title>
<style>
.checkbox{
	padding-left: 0px;
}
div.in-line{
	margin-top:5px;
}
div.in-line label{
	width:70px;
	text-align:right;
}
#searchBtn{
	text-align:right;
}
.form-horizontal .form-actions {
padding-left: 0px;
}
#newBtn{
	margin-left:10px;
}
</style>
</head>

<body>

	<div class="container-fluid">
		<div id="market" class="row-fluid">
			<div>
				<ul class="breadcrumb">
					<li><a href="#">学术讨论</a> <span class="divider">/</span></li>
					<li><a href="#">话题管理</a></li>
				</ul>
			</div>

			<div class="box">
				<div class="box-header well" data-original-title>
					<h2>
						<i class="icon-th"></i> 学习小组话题管理
					</h2>

					<div class="box-icon">
						<a href="#" class="btn btn-setting btn-round"><i
							class="icon-cog"></i></a> <a href="#"
							class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
						<a href="#" class="btn btn-close btn-round"><i
							class="icon-remove"></i></a>
					</div>
				</div>
				<div class="box-content">
					<div id="search-form">
					<form id="searchForm" method="post" class="form-search span12" action="<c:url value="/admin/study/topic/search"/>">
						<div class="in-line">
						<label>院系专业：</label>
						<select data-placeholder="全部" id="sorts_0" name="sortId" data-rel="chosen">
							<option value="0">全部</option>
							
						</select>
						<label>学习小组：</label>
						<select data-placeholder="全部" id="forumId" name="forumId" data-rel="chosen">
							<option value="0">全部</option>
							
						</select>
						<input type="hidden" name="pageNum" id="pageNum" value="${searchForm.pageNum }">
						<input type="hidden" name="infoId" id="infoId" value="${searchForm.infoId }">
						</div>
						<div class="in-line">
						<label>发表时间：</label>
						<input class="input-large datepicker"  name="startTime" id="date1" 
										type="text" value="" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至：
						<input class="input-large datepicker" name="endTime" id="date2" 
										type="text" value="" >
						</div>
						<div class="in-line">
						<label>标题：</label>
						<input type="text" name="title" id="title" value="${searchForm.title }" 
								class="input-large search-query">
						<label>作者：</label>
						<input type="text" name="authors" id="authors" value="${searchForm.authors }" 
								class="input-large search-query">
						<a href="<c:url value="/admin/study/addTopic"/>" id="newBtn" class="btn btn-danger pull-right">发表话题</a>
						<button type="button" id="searchBtn" class="btn btn-success pull-right">&nbsp;&nbsp;搜索&nbsp;&nbsp;</button>
						
						</div>
					</form>
					</div>
					<table id="userInfo" class="table table-striped table-bordered ">
						<thead>
							<tr>
								<th>标题</th>
								<th>小组名称</th>
								<th>作者</th>
								<th>回复</th>
								<th>浏览</th>
								<th>最后发表</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach var="topic" items="${pageModel.result }" varStatus="status">
								<tr>
									<td>${topic.subject }</td>
									<td>${topic.name }</td>
									<td>${topic.author } </td>
									<td>${topic.replies }</td>
									<td>${topic.views }</td>
									<td>${topic.lastPostDate }</td>
									<td><a href="javascript:edit('${topic.topicId }')"><i
											class="icon-edit"></i></a> &nbsp;&nbsp; <a
										href="javascript:del('${topic.topicId }')"><i class="icon-minus"></i></a></td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<div id="mypager" class="mypager"></div>
					<div>
						<hr>
					</div>
					
					
				</div>
			</div>
		</div>
		<!--/fluid-row-->

	</div>
	<!--/.fluid-container-->

	<jsp:include page="../frame/scripts.jsp"></jsp:include>
	<script type="text/javascript">
	var pageNum = "${pageModel.pageNum}";
	var totalPage = "${pageModel.totalPage}";
	var numPerPage = "${pageModel.numPerPage}";
	
	$(document).ready(function(){
				
		$('.datepicker').datepicker('option', 'dateFormat', 'yy-mm-dd'); 
		
		$( "#date1" ).datepicker( "setDate", "${searchForm.startTime}" );
		$( "#date2" ).datepicker( "setDate", "${searchForm.endTime}" );
		
		$('#mypager').bootstrapPaginator({
			currentPage:pageNum,
			totalPages:totalPage,
			numberOfPages:numPerPage,
			onPageClicked:function(event, originalEvent, type,page){
				$("input[name='pageNum']").val(page);
				$("#searchForm").submit();
			}
		});
		
		$('#searchBtn').click(function(){
			$("#searchForm").submit();
		})
		
		//初始化院系专业
		$.ajax({
			url:'<c:url value="/admin/study/faculty/tree" />',
			dataType:'json',
			success:function(data){
				//搜索表单初始化版块下拉框
				createTree(data,"sorts");
				//设置选中
				$("#sorts_0").val("${searchForm.sortId}");
				$("#sorts_0").trigger("change");
				
				//增加下拉框样式
				//$('[data-rel="chosen"],[rel="chosen"]').chosen();
			}
		})
		
		$("#sorts_0").change(function(){
			$("#forumId").html("<option value='0'>全部</option>");
			var sortId = $(this).val();
			$.ajax({
				url:'<c:url value="/admin/study/group/list" />',
				dataType:'json',
				data:{sortId:sortId},
				success:function(data){
					$.each(data,function(i,item){
						$("#forumId").append("<option value='"+item.forumId+"'>"+item.name+"</option>");	
					})
					//初始化数据
					$("#forumId").val("${searchForm.forumId}");
				}
			})
		})
		
		
	})
	
	function createTree(data,tagId){
		$.each(data,function(i,item){
			//生成节点
			createNode(item,tagId);
			if(item.children.length > 0){
				//生成子节点
				createTree(item.children,tagId);
			}
		})
	}

	function createNode(item,tagId){
		var $parent_select = $("#"+tagId+"_"+item.sortParent);
		var str = '';
		if(item.children.length > 0){
			str += '<optgroup id="'+tagId+'_'+item.sortId+'" label="'+item.sortName+'">';
			str += '</optgroup>';
		}else{
			str += '<option value='+item.sortId+'>'+item.sortName+'</option>';
		}
		$parent_select.append(str);
	}
	
	function edit(topicId){
		window.location.href = '<c:url value="/admin/forum/topic/'+topicId+'"/>';
	}
	
	function del(topicId){
		if(confirm("确定要删除吗？")){
			$("#infoId").val(topicId);
			$("#searchForm").submit();
		}
	}
	
	</script>
	
</body>
</html>
